<?php
namespace backend\controllers;

use Yii;
use yii\web\Controller;
use backend\models\Admin;
/**
 * Site controller
 */
class LoginController extends Controller
{
    public $layout = 'common';


    public function actionIndex()
    {
    	if(Yii::$app->request->post())
    	{
    		$data=Yii::$app->request->post();
    		$admin=Admin::find()->where(['admin_name'=>$data['Admin']['admin_name'],'admin_pwd'=>md5($data['Admin']['admin_pwd'])])->one();
    		if($admin)
    		{
    			$session = Yii::$app->session;
    			$session->open();
    			$_SESSION['user']=$admin;
    			echo "<script>alert('登录成功！！！'),location.href='?r=position/add'</script>";
    		}else{
    			echo "<script>alert('用户名或密码错误！！！'),location.href='?r=login/index'</script>";
    		}
    		// print_r($admin);
    	}else{
    		$model=new Admin;
            return $this->renderPartial('index',['model'=>$model]);
    	}
    	
    }

}